<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template_layout_lrt.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
	<style>
		.ui-dialog {
			top: 100px !important;
		}
		.col-md-9 .box-header{
			height:0px;padding:0px;margin:0px;
		}
		.box-body{
			padding-top:1px !important;
		}
		.col-md-9 .slimScrollDiv{
			height:750px !important;
		}
	</style>
	</ui:define>
	<ui:define name="top-box-tools">
		<h:form id="btnForm">
			<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
				<p:commandButton value="是" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
				<p:commandButton value="否" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
			</p:confirmDialog>
			<p:growl id="msgs" showDetail="true" />
			<p:toolbar id="btnBar"
				rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_sq') or
					s:hasPermission(session,'xtsz_xtqx_qxgl_jssz')}">
				<f:facet name="left">
					<p:commandButton icon="fa fa-hand-paper-o" value="功能授权" id="savebtn"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_sq') &amp;&amp; orgFunctionController.currentSelectRole == null }"
						update="grantPermissionForm:treeTable grantPermissionDialog"
						actionListener="#{orgFunctionController.preGrantPermission()}"
						style="font-weight:normal;margin-left:3px" oncomplete="PF('grantPermissionDialog').show()"
						disabled="#{orgFunctionController.selectedNode == null}" />
					<p:commandButton icon="fa fa-hand-paper-o" value="角色授权" id="roleGrantBtn"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_jsgl_sq') &amp;&amp; orgFunctionController.currentSelectRole != null}"
						update="grantPermissionForm:treeTable grantPermissionDialog"
						actionListener="#{orgFunctionController.preGrantPermission()}"
						style="font-weight:normal;margin-left:3px"
						oncomplete="PF('grantPermissionDialog').show()"/>
					<p:commandButton icon="fa fa-group" value="角色设置" id="roleedit"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_jssz')}"
						update="grantPermissionForm:treeTable msgs"
						disabled="#{orgFunctionController.selectedNode == null}"
						actionListener="#{orgFunctionController.openGrantRoleDialog()}" style="font-weight:normal">
						<p:ajax event="dialogReturn" listener="#{orgFunctionController.dialogCallBack}"
							update=":rightForm leftForm:tree msgs" />
					</p:commandButton>
					<p:commandButton icon="fa fa-hand-paper-o" value="变电站设置" 
						rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_bdzsz')}" 
						update="substationSetDialog" 
						disabled="#{orgFunctionController.selectedNode == null}" 
						style="font-weight:normal;margin-left:3px" 
						actionListener="#{orgFunctionController.preSettingSubstation()}" 
						oncomplete="PF('substationSetDialog').show()"/>
					
					<!-- 角色的功能按钮 -->
					<span class="ui-separator"> <span
						class="ui-icon ui-icon-grip-dotted-vertical" />
					</span>
					<p:commandButton value="新建角色" id="newBtn" icon="ui-icon-document"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_xj')}"
						actionListener="#{orgFunctionController.preCreateRole}"
						update=":roleForm:rolepg roleTreeForm:roleTree" style="margin-left: 3px;"
						disabled="#{orgFunctionController.selectedNode != null}"
						oncomplete="PF('newDialog').show()" />
					<p:commandButton value="编辑角色" id="editBtn" icon="ui-icon-pencil"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_bj')}"
						disabled="#{orgFunctionController.currentSelectRole == null}"
						update=":roleForm:rolepg" oncomplete="PF('newDialog').show()"
						style="margin-left: 3px;" />
					<p:commandButton value="删除角色" id="deleteBtn" icon="ui-icon-trash"
						rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_sc')}"
						disabled="#{orgFunctionController.currentSelectRole == null}"
						actionListener="#{orgFunctionController.deleteRole}"
						update=":roleTreeForm:roleTree btnBar msgs :rightForm"
						style="margin-right:3px">
						<p:confirm header="提示" message="您确定要删除该角色吗？删除后该角色将不可用！"
							icon="ui-icon-alert" />
					</p:commandButton>
					<!-- 快捷键功能按钮 -->
					<span class="ui-separator"> <span
						class="ui-icon ui-icon-grip-dotted-vertical" />
					</span>
					<p:commandButton value="重置权限" id="oneKeySet" icon="ui-icon-trash" 
						rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_yjzz')}" 
						actionListener="#{orgFunctionController.oneKeySet}"
						update="rightForm msgs"
						style="margin-right:3px">
						<p:confirm header="提示" message="您确定要清除权限缓存吗？"
							icon="ui-icon-alert" />
					</p:commandButton>
				</f:facet>
			</p:toolbar>
		</h:form>
	</ui:define>
	<ui:define name="left-box-title">
		&nbsp;组织机构
	</ui:define>
	<ui:define name="left-box-body">
		<h:form id="leftForm">
			<p:tree value="#{orgFunctionController.root}" var="node" dynamic="true" id="tree"
				widgetVar="tree" animate="true" selectionMode="multiple"
				selection="#{orgFunctionController.selectedNodes}" style="border:0">
				<p:ajax event="expand" update="tree :btnForm:savebtn"
					listener="#{orgFunctionController.onNodeExpand}" />
				<p:ajax event="select" update=":btnForm:btnBar :roleTreeForm:roleTree :rightForm :btnForm:savebtn"
					listener="#{orgFunctionController.onNodeSelect}" />
				<p:ajax event="unselect" update=":btnForm:btnBar :rightForm :btnForm:savebtn"
					listener="#{orgFunctionController.onNodeUnSelect}" />
				<p:treeNode type="dept" icon="fa fa-home">
					<h:outputText value="#{node}" />
				</p:treeNode>
				<p:treeNode type="personnel" icon="fa fa-user">
					<h:outputText value="#{node}" />
				</p:treeNode>
				<p:treeNode type="personnelr" icon="fa  fa-user">
					<h:outputText value="#{node}" />
				</p:treeNode>
			</p:tree>
		</h:form>
		<h:form id="roleTreeForm">
			<p:tree value="#{orgFunctionController.roleRoot}" var="node" dynamic="true" id="roleTree"
				widgetVar="roleTree" animate="true" selectionMode="multiple" selection="#{orgFunctionController.roleSelectedNodes}" style="border:0">
					<p:ajax event="select" update=":rightForm :btnForm:btnBar :leftForm:tree" listener="#{orgFunctionController.onRoleNodeSelect}" />
					<p:ajax event="unselect" update=":rightForm :btnForm:btnBar" listener="#{orgFunctionController.onRoleNodeUnSelect}" />
					<p:treeNode type="root" icon="fa fa-home">
						<h:outputText value="#{node}" />
					</p:treeNode>
					<p:treeNode icon="fa fa-user-circle-o">
						<h:outputText value="#{node}" />
					</p:treeNode>
				</p:tree>
		</h:form>
	</ui:define>
	<ui:define name="right-box-body">
		<h:form id="rightForm" >
			<p:tabView id="tables">
	        	<p:tab title="所属权限" id="roles">
					<p:treeTable id="treeTable" widgetVar="treeTable" emptyMessage="无数据"
						value="#{orgFunctionController.funcRoot}" var="fun">
						<p:column headerText="名称" style="width:30%">
							<h:outputText value="#{fun.function.name} " />
						</p:column>
		
						<p:column headerText="权限" style="text-align:center;width:15%">
							<h:outputText rendered="#{fun.permission=='DENY'}" style="color:red" value="拒绝" />
							<h:outputText rendered="#{fun.permission=='ALLOW'}" style="color:green" value="允许" />
						</p:column>
		
						<p:column headerText="类型" style="text-align:center;width:15%">
							<h:outputText styleClass="fa fa-bars" rendered="#{fun.function.type.equals('menu')}"
								value=" 菜单" style="color:#006400" />
							<h:outputText styleClass="fa fa-home" rendered="#{fun.function.type.equals('page')}"
								value=" 页面" style="color:#433" />
							<h:outputText styleClass="fa fa-dot-circle-o"
								rendered="#{fun.function.type.equals('pagemenu')}" value="  页内菜单" style="color:#CD2990" />
							<h:outputText styleClass="fa fa-wrench" rendered="#{fun.function.type.equals('operation')}"
								value="  操作" style="color:blue" />
						</p:column>
					</p:treeTable>
		      	</p:tab>
		      	<p:tab title="人员列表" rendered="#{orgFunctionController.currentSelectRole != null}">
					<p:treeTable scrollable="true" id="rolePersonTable" widgetVar="rolePersonTable" 
						value="#{orgFunctionController.rolePersonRoot}" var="r" emptyMessage="暂无数据">
						<p:column headerText="名称" style="width:30%">
							<h:outputText value="#{r.name} " />
						</p:column>
						<p:column headerText="电话" style="width:35%">
							<h:outputText value="#{r.telphone}" />
						</p:column>
						<p:column headerText="状态" style="width:35%">
							<h:outputText rendered="#{r.status.equals('正常')}" style="color:#2399e5" value="#{r.status}" />
							<h:outputText rendered="#{r.status.equals('锁定')}" style="color:red" value="#{r.status}" />
						</p:column>
					</p:treeTable>
		      	</p:tab>
		      	<p:tab title="所属角色" rendered="#{orgFunctionController.selectedNode.type == 'personnel' ||  orgFunctionController.selectedNode.type == 'personnelr'}">
		      		<p:dataTable id="personRoleTable" var="r" value="#{orgFunctionController.personRoles}" style="text-align:center" emptyMessage="暂无数据">
		      			<p:column headerText="角色名称">
		      				<p:outputLabel value="#{r.name}" />
		      			</p:column>
		      			<p:column headerText="角色描述">
		      				<p:outputLabel value="#{r.description}" />
		      			</p:column>
		      		</p:dataTable>
		      	</p:tab>
		      	<!-- 变电站tab -->
		      	<p:tab title="变电站" rendered="#{orgFunctionController.selectedNode != null}">
		      		<p:treeTable id="orgSubstationTreeTable" scrollable="true" emptyMessage="无数据" scrollHeight="500" style="margin-top:6px" 
						widgetVar="orgSubstationTreeTable" value="#{orgFunctionController.orgSubstationRoot}" var="orgSub">
						<p:column headerText="名称" style="width:30%">
							<h:outputText value="#{orgSub.name} " />
						</p:column>
						<p:column headerText="权限" style="text-align:center;width:25%">
							<h:outputText rendered="#{orgSub.permission=='DENY'}" style="color:red" value="拒绝" />
							<h:outputText rendered="#{orgSub.permission=='ALLOW'}" style="color:green" value="允许" />
						</p:column>
					</p:treeTable>
		      	</p:tab>
       		</p:tabView>
		</h:form>
		
		<p:dialog widgetVar="grantPermissionDialog" id="grantPermissionDialog" resizable="false"
			header="#{orgFunctionController.grantPerTitle}" modal="true" width="1200" height="700">
			<p:outputLabel value="提示:选择多个则只给最后一个对象授权" style="color:red" rendered="#{orgFunctionController.showNotice()}"/>
			<h:form id="grantPermissionForm">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="保存" process="@this" actionListener="#{orgFunctionController.save()}"
							update=":rightForm btnForm:msgs" oncomplete="PF('grantPermissionDialog').hide()"
							styleClass="margin-left:10px" />
					</f:facet>
				</p:toolbar>
				<p:treeTable scrollable="true" scrollHeight="500" style="margin-top:6px" id="treeTable"
					widgetVar="treeTable" value="#{orgFunctionController.grantRoot}" var="fun">
					<p:ajax event="expand" listener="#{orgFunctionController.onFunNodeExpand}" />
					<p:ajax event="collapse" listener="#{orgFunctionController.onFunNodeCollapse}" />
					<p:column headerText="名称" style="width:30%">
						<h:outputText  value="#{fun.function.name} " />
					</p:column>

					<p:column headerText="地址" style="width:35%">
						<h:outputText value="#{fun.function.url}" />
					</p:column>

					<p:column headerText="类型" style="text-align:center;width:10%">
						<h:outputText styleClass="fa fa-home" rendered="#{fun.function.type.equals('page')}"
							value="  页面" style="color:#433" />
						<h:outputText styleClass="fa fa-dot-circle-o"
							rendered="#{fun.function.type.equals('pagemenu')}" value="  页内菜单" style="color:#CD2990" />
						<h:outputText styleClass="fa fa-bars" rendered="#{fun.function.type.equals('menu')}"
							value="  菜单" style="color:#006400" />
						<h:outputText styleClass="fa fa-wrench" rendered="#{fun.function.type.equals('operation')}"
							value="  操作" style="color:blue" />
					</p:column>
					<p:column headerText="权限" value="#{fun.permission}" style="padding:0px;width:25%">
						<p:selectOneRadio widgetVar="#{fun.function.id}"
							rendered="#{!fun.function.type.equals('root') &amp;&amp; !fun.function.type.equals('approot')}" value="#{fun.permission}"
							style="padding:0;margin:0">
							<p:ajax event="click" update="treeTable" listener="#{orgFunctionController.changeRadio}" />
							<f:selectItem itemLabel="允许" itemValue="ALLOW" />
							<f:selectItem itemLabel="拒绝" itemValue="DENY" />
							<f:selectItem itemLabel="无" itemValue="" />
						</p:selectOneRadio>
					</p:column>
				</p:treeTable>
			</h:form>
		</p:dialog>
		
		<!-- 变电站设置dialog -->
		<p:dialog widgetVar="substationSetDialog" id="substationSetDialog" resizable="false"
			header="变电站设置" modal="true" width="1200" height="650">
			<h:form id="substationSetForm">
				<p:toolbar>
					<f:facet name="left">
						<p:autoComplete id="startionSearch" dropdown="true"
							placeholder="变电站首字母查询" scrollHeight="400"
							value="#{orgFunctionController.stationSearch}"
							style="margin-right:10px"
							completeMethod="#{stationDataViewController.complateStation}">
						</p:autoComplete>
						<p:commandButton value="查询" icon="ui-icon-search" 
							rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_bdzcx')}" 
							actionListener="#{orgFunctionController.searchBySubstation()}"
							update="substationSetForm" />
						<p:commandButton value="重置" icon="ui-icon-refresh" 
							rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_bdzzz')}" 
							actionListener="#{orgFunctionController.resetSubstation()}"
							update="startionSearch substationSetForm" />
						<p:commandButton value="保存" actionListener="#{orgFunctionController.substationSetting()}" 
							rendered="#{s:hasPermission(session,'xtsz_xtqx_qxgl_bdzbc')}" 
							update="rightForm btnForm:msgs" oncomplete="PF('substationSetDialog').hide()" />
					</f:facet>
				</p:toolbar>
				<p:treeTable scrollable="true" scrollHeight="500" style="margin-top:6px" id="substationTreeTable"
					widgetVar="substationTreeTable" value="#{orgFunctionController.substationRoot}" var="sub">
					<p:column headerText="名称" style="width:30%">
						<h:outputText value="#{sub.name} " />
					</p:column>
					<p:column headerText="权限" value="#{sub.permission}" style="padding:0px;width:25%">
						<p:selectOneRadio widgetVar="#{sub.id}" value="#{sub.permission}"
							style="padding:0;margin:0">
							<p:ajax event="click" update="substationTreeTable" listener="#{orgFunctionController.substationRadio}" />
							<f:selectItem itemLabel="允许" itemValue="ALLOW" />
							<f:selectItem itemLabel="拒绝" itemValue="DENY" />
							<f:selectItem itemLabel="无" itemValue="" />
						</p:selectOneRadio>
					</p:column>
				</p:treeTable>
			</h:form>
		</p:dialog>
		
		<p:dialog widgetVar="newDialog" id="newDialog" header="新建角色"
			modal="true" width="600" height="300">
			<h:form id="roleForm">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="保存" icon="ui-icon-disk"
							oncomplete="PF('newDialog').hide()"
							actionListener="#{orgFunctionController.saveRole()}"
							update=":roleTreeForm:roleTree :btnForm:btnBar :btnForm:msgs" />
					</f:facet>
				</p:toolbar>
				<p:panelGrid columns="2" id="rolepg"
					style="margin-top:10px; width:100%;border:0">
					<h:outputText value="角色名称" />
					<p:inputText
						value="#{orgFunctionController.currentSelectRole.name}"
						style="width:100%" />
					<h:outputText value="角色描述" />
					<p:inputTextarea
						value="#{orgFunctionController.currentSelectRole.description}"
						style="width:100%" />
				</p:panelGrid>
			</h:form>
		</p:dialog>
	</ui:define>
	<ui:define name="contentend">
	   <script>
		   window.onload=function(){

		   }
	   </script>
	</ui:define>
</ui:composition>